#include "square.h"
#include <assert.h>
#include "GL\glut.h"

int Square::sel_file = -1;
int Square::sel_rank = -1;

void Square::select(int file, int rank){
	if(file > 0 && file < 9 && rank > 0 && rank < 9){
		sel_file = file;
		sel_rank = rank;
	}else{
		unselect();
	}
}
void Square::unselect(){
	sel_rank = -1;
	sel_file = -1;
}
Square::Square(){
	rank = 1;
	file = 1;
	color = WHITE;
}
Square::Square(int r, int f){
	assert(0 < r && r <= 9);
	assert(0 < f && f <= 9);
	sel_file = -1;
	sel_rank = -1;
	rank = r;
	file = f;
	if((r + f)%2 == 0){
		color = WHITE;
	}else{
		color = BLACK;
	}
}

void Square::drawSquare(){
	glTranslatef(file-1, 0, rank);

	if(color == WHITE){
		glColor3f(1,1,1);
	}else{
		glColor3f(0.2,0.2,0.2);
	}
	if(file == sel_file && rank == sel_rank){
		glColor3f(0.8, 0.2, 0.2);
	}
	glBegin(GL_QUADS);
    glNormal3f(0, 1, 0);
    glVertex3f(0, 0, 0);
    glVertex3f(0, 0, -1);
    glVertex3f(1, 0, -1);
    glVertex3f(1, 0, 0);
    glEnd();
}